package com.dhj.top100;

import java.util.Arrays;

public class MoveZeroes {
    public static void main(String[] args) {
        int[] nums = new int[]{0,1,0,3,12};
        moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }

    public static void moveZeroes(int[] nums) {
        int index = 1;
        for (int i = 0; i + index < nums.length; i++) {
            if (nums[i] == 0 && nums[i + index] != 0) {
               int temp = nums[i + index];
               nums[i + index] = nums[i];
               nums[i] = temp;
            }
            if (nums[i] == 0 && nums[i + index] == 0) {
                index ++; i--;
            }
        }
    }
}
